
console.log("TickStrem V2.0 Auth MingZeY");//调用一次，避免调用该API造成的计时误差

require("Constants");
require("util");
require("Prototype");
require("Registry");
require("Adapter");
require("TimeDilation");
require("Intent");
require("Drive");
require("StateTrack");

global.TickStream = (function(){

    let handleRoom = function(room){
        //console.log(room.name);
    }


    return function(){

        /**
         * 每个Tick的处理流程
         */

        //遍历所有房间
        let roomArr = Registry.Room;
        for(let i in roomArr){
            handleRoom(roomArr[i]);
        }

        //遍历Creep并加入对应Spawn生成队列
        for(let name of Registry.Creeps){

            let creep = R[name];
            
            //Creep是否存在
            if(Game.creeps[name] == undefined){
                //获取spawn
                let spawn = Game.spawns[creep.spawn.spawnName];

                //获取是否存在目标的任务列表中
                if(!spawn.isExistInPool(name)){
                    //加入队列
                    spawn.spawnInPool(creep.body,name);

                    //触发JoinPlan事件
                    util.getValue(() => R[name].event.onJoinPlan,() => {})();
                }
            }
        }

        //遍历所有Spawn并触发刷新
        for(let i in Game.spawns){
            let spawning = Game.spawns[i].flashPool();
            if(spawning != null){
                //触发事件
                util.getValue(() => R[spawning.name].event.onSpawn,() => {})(spawning);
                util.getValue(() => R[spawning.name].event.onSpawning,() => {})(spawning);
            }
        }




        //intent调用API
        intent.handle();
        TimeDilation.flash();
    }
    
})();